/*************************************************************************
 *  Copyright © 2023-2030 FXB CO.,LTD. All rights reserved.
 *------------------------------------------------------------------------
 *  公司：DefaultCompany
 *  项目：UnityPackageCreator
 *  文件：PackageCreatorWindow.cs
 *  作者：Administrator
 *  日期：2024/11/20 20:18:52
 *  功能：Nothing
*************************************************************************/

using Newtonsoft.Json.Linq;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Text.RegularExpressions;
using UnityEditor;
using UnityEditorInternal;
using UnityEngine;
using UnityPackageCreator.Runtime;
using Debug = UnityEngine.Debug;

namespace UnityPackageCreator.Editor
{
    public class PackageCreatorWindow : EditorWindow
    {
        public static PackageCreatorWindow instance;

        private bool isCreteScriptsFolder = true;
        private bool isCreteTestsFolder = false;
        private bool isCreateChangeLog = true;
        private bool isCreateReadme = true;

        private string packageName = "";
        private string version = "";
        private string displayName = "";
        private string description = "";
        private string unity = "";
        private string unityRelease = "";
        private string documentationUrl = "";
        private string changelogUrl = "";
        private string licensesUrl = "";
        private List<Dependency> dependencies = new List<Dependency>();
        private List<string> keywords = new List<string>();
        private Author author = new Author();
        private List<Sample> samples = new List<Sample>();

        private ReorderableList keywordsReorderableList;
        private ReorderableList samplesReorderableList;
        private ReorderableList dependenciesReorderableList;

        private bool autorToogleGroup;
        private Vector2 scrollPos;

        private bool packageNameWarning;
        private bool versionWarning;
        private bool displayNameWarning;
        private bool descriptionWarning;
        private bool unityWarning;
        private bool unityReleaseWarning;
        private bool documentationUrlWarning;
        private bool changelogUrlWarning;
        private bool licensesUrlWarning;
        private bool authorEmailWarning;
        private bool authorUrlWarning;

        private string packageNameWarningInfo;
        private string versionWarningInfo;
        private string displayNameWarningInfo;
        private string descriptionWarningInfo;
        private string unityWarningInfo;
        private string unityReleaseWarningInfo;
        private string documentationUrlWarningInfo;
        private string changelogUrlWarningInfo;
        private string licensesUrlWarningInfo;
        private string authorEmailWarningInfo;
        private string authorUrlWarningInfo;

        // 正则表达式模式，用于验证URL
        private readonly string UrlPattern = @"^(http|https)://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?$";

        // 正则表达式模式，用于验证Email
        private readonly string EmailPattern = @"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$";

        // 显示自定义窗口的方法
        [MenuItem("Window/Unity Package Creator")]
        public static void ShowWindow()
        {
            instance = GetWindow<PackageCreatorWindow>("Unity Package Creator");

            instance.Show();
        }

        private void OnEnable()
        {
            InitKeywordsList();
            InitSamplesList();
            InitDependenciesList();
        }

        private void OnGUI()
        {
            DrawGUI();
        }

        #region 绘制面板信息

        private void InitKeywordsList()
        {
            keywordsReorderableList = new ReorderableList(
                 keywords,
                 typeof(string),
                 true, // 是否可拖拽排序
                 true, // 是否显示标题
                 true, // 是否显示添加按钮
                 true  // 是否显示删除按钮
             );

            keywordsReorderableList.drawHeaderCallback = rect =>
            {
                EditorGUI.LabelField(rect, "Keywords", EditorStyles.boldLabel);
            };

            // 绘制每一项
            keywordsReorderableList.drawElementCallback = (rect, index, isActive, isFocused) =>
            {
                keywords[index] = EditorGUI.TextField(
                    new Rect(rect.x, rect.y + 2, rect.width, EditorGUIUtility.singleLineHeight),
                    keywords[index]
                );
            };

            // 添加项的回调
            keywordsReorderableList.onAddCallback = list =>
            {
                keywords.Add("");
            };

            // 删除项的回调
            keywordsReorderableList.onRemoveCallback = list =>
            {
                if (list.index >= 0 && list.index < keywords.Count)
                {
                    keywords.RemoveAt(list.index);
                }
            };
        }

        private void InitSamplesList()
        {
            samplesReorderableList = new ReorderableList(
                samples,
                typeof(Sample),
                true,  // draggable
                true,  // display header
                true,  // display add button
                true   // display remove button
            );

            samplesReorderableList.elementHeight = EditorGUIUtility.singleLineHeight;

            samplesReorderableList.drawHeaderCallback = rect =>
            {
                EditorGUI.LabelField(rect, "Samples", EditorStyles.boldLabel);
            };

            samplesReorderableList.drawElementCallback = (rect, index, isActive, isFocused) =>
            {
                var element = samples[index];
                rect.y += 2;
                float fieldWidth = rect.width;


                element.displayName = EditorGUI.TextField(
                    new Rect(rect.x, rect.y, fieldWidth, EditorGUIUtility.singleLineHeight),
                    "DisplayName",
                    element.displayName
                );

                element.description = EditorGUI.TextField(
                    new Rect(rect.x, rect.y + EditorGUIUtility.singleLineHeight + 2, fieldWidth, EditorGUIUtility.singleLineHeight),
                    "Description",
                    element.description
                );

                element.path = EditorGUI.TextField(
                    new Rect(rect.x, rect.y + EditorGUIUtility.singleLineHeight * 2 + 2 * 2, fieldWidth, EditorGUIUtility.singleLineHeight),
                    "Path",
                    element.path
                );
            };

            samplesReorderableList.onAddCallback = list =>
            {
                samplesReorderableList.elementHeight = EditorGUIUtility.singleLineHeight * 3 + 2 * 2 + 2 * 2;
                samples.Add(new Sample());
            };

            samplesReorderableList.onRemoveCallback = list =>
            {
                if (list.index >= 0 && list.index < samples.Count)
                {
                    samples.RemoveAt(list.index);
                    if (list.count == 0)
                        samplesReorderableList.elementHeight = EditorGUIUtility.singleLineHeight;
                }
            };
        }

        private void InitDependenciesList()
        {
            dependenciesReorderableList = new ReorderableList(
                dependencies,
                typeof(Dependency),
                true,  // draggable
                true,  // display header
                true,  // display add button
                true   // display remove button
            );

            dependenciesReorderableList.drawHeaderCallback = rect =>
            {
                EditorGUI.LabelField(rect, "Dependencies", EditorStyles.boldLabel);
            };

            dependenciesReorderableList.drawElementCallback = (rect, index, isActive, isFocused) =>
            {
                var element = dependencies[index];
                rect.y += 2;
                float fieldWidth_packageName = rect.width * 0.75f;
                float fieldWidth_version = rect.width - fieldWidth_packageName - 5;


                element.packageName = EditorGUI.TextField(
                    new Rect(rect.x, rect.y, fieldWidth_packageName, EditorGUIUtility.singleLineHeight),
                    element.packageName
                );

                element.version = EditorGUI.TextField(
                    new Rect(rect.x + fieldWidth_packageName + 5, rect.y, fieldWidth_version, EditorGUIUtility.singleLineHeight),
                    element.version
                );
            };

            dependenciesReorderableList.onAddCallback = list =>
            {
                dependencies.Add(new Dependency());
            };

            dependenciesReorderableList.onRemoveCallback = list =>
            {
                if (list.index >= 0 && list.index < dependencies.Count)
                {
                    dependencies.RemoveAt(list.index);
                }
                else
                {
                    Debug.LogWarning("Invalid index for removal.");
                }
            };
        }

        /// <summary>
        /// 绘制面板
        /// </summary>
        private void DrawGUI()
        {
            GUILayout.Space(5f);

            GUILayout.Label("Package Config", new GUIStyle { fontSize = 20, padding = new RectOffset() { left = 5 }, fontStyle = FontStyle.Bold, normal = { textColor = Color.white } }); ;

            GUILayout.Space(5f);

            scrollPos = EditorGUILayout.BeginScrollView(scrollPos,EditorStyles.helpBox);

            DrawPackageOptions();

            GUILayout.Space(5f);

            DrawPackageConfigGUI();

            EditorGUILayout.EndScrollView();

            //创建之前要验证面板信息
            if (GUILayout.Button("Create Package"))
            {
                if (!ValidatePackageInfo()) return;

                string selectPath = EditorUtility.OpenFolderPanel("Select Folder for New Package", "", "");

                if (!ValidatePackagePath(selectPath)) return;

                bool isSuccess = CreateNewPackage(selectPath, packageName, out string packagePath);

                if (isSuccess == false) return;

                InstallPackage(selectPath, packagePath);
            }
        }

        /// <summary>
        /// 绘制package选项
        /// </summary>
        private void DrawPackageOptions()
        {
            isCreteScriptsFolder = EditorGUILayout.ToggleLeft("Is Crete Scripts Folder", isCreteScriptsFolder);
            GUILayout.Space(5f);

            isCreteTestsFolder = EditorGUILayout.ToggleLeft("Is Crete Tests Folder", isCreteTestsFolder);
            GUILayout.Space(5f);

            isCreateChangeLog = EditorGUILayout.ToggleLeft("Is Create ChangeLog File", isCreateChangeLog);
            GUILayout.Space(5f);

            isCreateReadme = EditorGUILayout.ToggleLeft("Is Create ReadMe File", isCreateReadme);
        }

        /// <summary>
        /// 绘制package配置信息
        /// </summary>
        private void DrawPackageConfigGUI()
        {
            DrawPackageName();

            DrawVersion();

            DrawDisplayName();

            DrawDescription();

            DrawUnityVersion();

            DrawUnityRelease();

            DrawDocumentationUrl();

            DrawChangelogUrl();

            DrawLicensesUrl();

            // dependencies ReorderableList
            dependenciesReorderableList.DoLayoutList();
            GUILayout.Space(5);

            // 绘制keywords ReorderableList
            keywordsReorderableList.DoLayoutList();

            DrawAuthorInfo();

            GUILayout.Space(5);

            // samples ReorderableList
            samplesReorderableList.DoLayoutList();
        }

        /// <summary>
        /// 绘制包名
        /// </summary>
        private void DrawPackageName()
        {
            if (packageNameWarning)
            {
                EditorGUILayout.HelpBox(packageNameWarningInfo, MessageType.Warning);
            }

            packageName = EditorGUILayout.TextField("Package Name *", packageName);
            if (!string.IsNullOrEmpty(packageName))
            {
                if (packageNameWarning)
                    packageNameWarning = false;
            }
        }

        /// <summary>
        /// 绘制包版本
        /// </summary>
        private void DrawVersion()
        {
            if (versionWarning)
            {
                EditorGUILayout.HelpBox(versionWarningInfo, MessageType.Warning);
            }
            version = EditorGUILayout.TextField("Version *", version);
            if (!string.IsNullOrEmpty(version))
            {
                if (versionWarning)
                    versionWarning = false;
            }
        }

        /// <summary>
        /// 绘制展示名
        /// </summary>
        private void DrawDisplayName()
        {
            if (displayNameWarning)
            {
                EditorGUILayout.HelpBox(displayNameWarningInfo, MessageType.Warning);
            }
            displayName = EditorGUILayout.TextField("Display Name *", displayName);
            if (!string.IsNullOrEmpty(displayName))
            {
                if (displayNameWarning)
                    displayNameWarning = false;
            }
        }

        /// <summary>
        /// 绘制包描述
        /// </summary>
        private void DrawDescription()
        {
            if (descriptionWarning)
            {
                EditorGUILayout.HelpBox(descriptionWarningInfo, MessageType.Warning);
            }
            EditorGUILayout.LabelField("Description * ");
            description = EditorGUILayout.TextArea(description, GUILayout.Height(50));
            if (!string.IsNullOrEmpty(description))
            {
                if (descriptionWarning)
                    descriptionWarning = false;
            }
        }

        /// <summary>
        /// 绘制Unity版本
        /// </summary>
        private void DrawUnityVersion()
        {
            if (unityWarning)
            {
                EditorGUILayout.HelpBox(unityWarningInfo, MessageType.Warning);
            }
            unity = EditorGUILayout.TextField("Unity Version *", unity);
            if (!string.IsNullOrEmpty(unity))
            {
                if (unityWarning)
                    unityWarning = false;
            }
        }

        /// <summary>
        /// 绘制Unity 发行版
        /// </summary>
        private void DrawUnityRelease()
        {
            if (unityReleaseWarning)
            {
                EditorGUILayout.HelpBox(unityReleaseWarningInfo, MessageType.Warning);
            }
            unityRelease = EditorGUILayout.TextField("Unity Release *", unityRelease);
            if (!string.IsNullOrEmpty(unityRelease))
            {
                if (unityReleaseWarning)
                    unityReleaseWarning = false;
            }
        }

        /// <summary>
        /// 绘制文档地址
        /// </summary>
        private void DrawDocumentationUrl()
        {
            if (documentationUrlWarning)
            {
                EditorGUILayout.HelpBox(documentationUrlWarningInfo, MessageType.Warning);
            }
            documentationUrl = EditorGUILayout.TextField("Documentation URL", documentationUrl);
            if (string.IsNullOrEmpty(documentationUrl) || (!string.IsNullOrEmpty(documentationUrl) && IsValidUrl(documentationUrl)))
            {
                if (documentationUrlWarning)
                    documentationUrlWarning = false;
            }
        }

        /// <summary>
        /// 绘制日志地址
        /// </summary>
        private void DrawChangelogUrl()
        {
            if (changelogUrlWarning)
            {
                EditorGUILayout.HelpBox(changelogUrlWarningInfo, MessageType.Warning);
            }
            changelogUrl = EditorGUILayout.TextField("Changelog URL", changelogUrl);
            if (string.IsNullOrEmpty(changelogUrl) || (!string.IsNullOrEmpty(changelogUrl) && IsValidUrl(changelogUrl)))
            {
                if (changelogUrlWarning)
                    changelogUrlWarning = false;
            }
        }

        /// <summary>
        /// 绘制证书地址
        /// </summary>
        private void DrawLicensesUrl()
        {
            if (licensesUrlWarning)
            {
                EditorGUILayout.HelpBox(licensesUrlWarningInfo, MessageType.Warning);
            }
            licensesUrl = EditorGUILayout.TextField("Licenses URL", licensesUrl);
            if (string.IsNullOrEmpty(licensesUrl) || (!string.IsNullOrEmpty(licensesUrl) && IsValidUrl(licensesUrl)))
            {
                if (licensesUrlWarning)
                    licensesUrlWarning = false;
            }
        }

        private void DrawAuthorInfo()
        {
            if (authorEmailWarning)
            {
                EditorGUILayout.HelpBox(authorEmailWarningInfo, MessageType.Warning);
            }

            if (authorUrlWarning)
            {
                EditorGUILayout.HelpBox(authorUrlWarningInfo, MessageType.Warning);
            }

            autorToogleGroup = EditorGUILayout.BeginFoldoutHeaderGroup(autorToogleGroup, "Author");
            if (autorToogleGroup)
            {
                EditorGUI.indentLevel += 1;
                author.name = EditorGUILayout.TextField("Name", author.name);
                author.email = EditorGUILayout.TextField("Email", author.email);
                author.url = EditorGUILayout.TextField("Url", author.url);

                EditorGUI.indentLevel -= 1;
            }

            EditorGUILayout.EndFoldoutHeaderGroup();

            if (authorEmailWarning &&
                (string.IsNullOrEmpty(author.email)
                || (!string.IsNullOrEmpty(author.email) && IsValidEmail(author.email))
                ))
            {
                authorEmailWarning = false;
            }

            if (authorUrlWarning
                && (string.IsNullOrEmpty(author.url)
                || (!string.IsNullOrEmpty(author.url) && IsValidUrl(author.url))
                ))
            {
                authorUrlWarning = false;
            }
        }
        #endregion

        #region package 包验证

        /// <summary>
        /// 验证包信息
        /// </summary>
        private bool ValidatePackageInfo()
        {
            packageNameWarning = false;
            versionWarning = false;
            displayNameWarning = false;
            descriptionWarning = false;
            unityWarning = false;
            unityReleaseWarning = false;
            documentationUrlWarning = false;
            changelogUrlWarning = false;
            licensesUrlWarning = false;
            authorEmailWarning = false;
            authorUrlWarning = false;

            if (string.IsNullOrEmpty(packageName))
            {
                packageNameWarning = true;
                packageNameWarningInfo = "Please enter the package name";
                return false;
            }

            if (string.IsNullOrEmpty(version))
            {
                versionWarning = true;
                versionWarningInfo = "Please enter the version";
                return false;
            }

            if (string.IsNullOrEmpty(displayName))
            {
                displayNameWarning = true;
                displayNameWarningInfo = "Please enter the display name";
                return false;
            }

            if (string.IsNullOrEmpty(description))
            {
                descriptionWarning = true;
                descriptionWarningInfo = "Please enter the description";
                return false;
            }

            if (string.IsNullOrEmpty(unity))
            {
                unityWarning = true;
                unityWarningInfo = "Please enter the unity version";
                return false;
            }

            if (string.IsNullOrEmpty(unityRelease))
            {
                unityReleaseWarning = true;
                unityReleaseWarningInfo = "Please enter the unity release";
                return false;
            }

            if (!string.IsNullOrEmpty(documentationUrl) && !IsValidUrl(documentationUrl))
            {
                documentationUrlWarning = true;
                documentationUrlWarningInfo = "Please enter a valid documentation Url";
                return false;
            }

            if (!string.IsNullOrEmpty(changelogUrl) && !IsValidUrl(changelogUrl))
            {
                changelogUrlWarning = true;
                changelogUrlWarningInfo = "Please enter a valid changelog Url";
                return false;
            }

            if (!string.IsNullOrEmpty(licensesUrl) && !IsValidUrl(licensesUrl))
            {
                licensesUrlWarning = true;
                licensesUrlWarningInfo = "Please enter a valid licenses Url";
                return false;
            }

            if (!string.IsNullOrEmpty(author.email) && !IsValidEmail(author.email))
            {
                authorEmailWarning = true;
                authorEmailWarningInfo = "Please enter a valid email address";
                return false;
            }

            if (!string.IsNullOrEmpty(author.url) && !IsValidUrl(author.url))
            {
                authorUrlWarning = true;
                authorUrlWarningInfo = "Please enter a valid Url";
                return false;
            }

            return true;
        }

        /// <summary>
        /// 网址验证
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        public bool IsValidUrl(string url)
        {
            if (string.IsNullOrWhiteSpace(url))
                return false;

            var regex = new Regex(UrlPattern, RegexOptions.IgnoreCase);
            return regex.IsMatch(url);
        }

        /// <summary>
        /// 邮箱验证
        /// </summary>
        /// <param name="email"></param>
        /// <returns></returns>
        public bool IsValidEmail(string email)
        {
            if (string.IsNullOrWhiteSpace(email))
                return false;

            var regex = new Regex(EmailPattern, RegexOptions.IgnoreCase);
            return regex.IsMatch(email);
        }

        /// <summary>
        /// 验证包路径
        /// </summary>
        /// <returns></returns>
        private bool ValidatePackagePath(string selectPath)
        {
            //无效路径
            if (string.IsNullOrEmpty(selectPath))
            {
                Debug.LogError("Invalid path, Please select a valid folder.");
                return false;
            }

            //如果你选择的文件夹本身就是个包，判断是否包含packagge.json文件是否存在，如果存在是不允许创建的
            if (File.Exists(Path.Combine(selectPath, "package.json")))
            {
                Debug.LogError("Creating packages within the package is not allowed, Please select a valid folder.");
                return false;
            }

            return true;
        }

        #endregion

        #region 创建包

        /// <summary>
        /// 创建一个新包
        /// </summary>
        /// <param name="packageName">包名称</param>
        /// <param name="selectPath">包放置的路径</param>
        private bool CreateNewPackage(string selectPath, string packageName, out string packagePath)
        {
            packagePath = Path.Combine(selectPath, packageName);
            if (Directory.Exists(packagePath))
            {
                Debug.LogError($"Directory already exists: {packagePath}");
                return false;
            }

            Directory.CreateDirectory(packagePath);

            CreatePackageFolder(packagePath, packageName);
            CreatePackageFile(packagePath);
            CreateChangeLogFile(packagePath);
            CreateReadMeFile(packagePath);

            Debug.Log($"Package created successfully at: {packagePath}");

            // 检查是否选择了有效的文件夹
            if (!string.IsNullOrEmpty(packagePath))
            {
                // 使用系统默认的文件浏览器打开文件夹
                Process.Start(new ProcessStartInfo(packagePath)
                {
                    UseShellExecute = true,
                    WindowStyle = ProcessWindowStyle.Minimized
                });
            }

            return true;
        }

        /// <summary>
        /// 创建package.json文件
        /// </summary>
        private void CreatePackageFile(string pacakgePath)
        {
            // Create package.json
            PackageConfigProcess.CreatePackageJson(pacakgePath, GetPackageJsonContent());
        }

        /// <summary>
        /// 获取包信息
        /// </summary>
        /// <returns></returns>
        private PackageConfig GetPackageJsonContent()
        {
            PackageConfig packageConfig = new PackageConfig();
            packageConfig.name = packageName;
            packageConfig.version = version;
            packageConfig.displayName = displayName;
            packageConfig.description = description;
            packageConfig.unity = unity;
            packageConfig.unityRelease = unityRelease;
            packageConfig.documentationUrl = documentationUrl;
            packageConfig.changelogUrl = changelogUrl;
            packageConfig.licensesUrl = licensesUrl;

            JObject dependenciesJObject = new JObject();
            dependencies.ForEach(dependency =>
            {
                JProperty property = new JProperty(dependency.packageName, dependency.version);
                dependenciesJObject.Add(property);
            });

            packageConfig.dependencies = dependenciesJObject;

            packageConfig.keywords = keywords;
            packageConfig.author = author;
            packageConfig.samples = samples;

            return packageConfig;
        }

        /// <summary>
        /// 创建CHANGELOG.md文件
        /// </summary>
        private void CreateChangeLogFile(string pacakgePath)
        {
            if (!isCreateChangeLog) return;
            // Create CHANGELOG.md
            string changeLogPath = Path.Combine(pacakgePath, "CHANGELOG.md");
            File.WriteAllText(changeLogPath, "# Changelog\nAll notable changes to this package will be documented in this file.\n\n");
        }

        /// <summary>
        /// 创建README.md文件
        /// </summary>
        private void CreateReadMeFile(string pacakgePath)
        {
            if (!isCreateReadme) return;
            // Create README.md
            string readmePath = Path.Combine(pacakgePath, "README.md");
            File.WriteAllText(readmePath, $"# {Path.GetFileName(pacakgePath)}\n\n");
        }

        /// <summary>
        /// 创建包文件夹
        /// </summary>
        private void CreatePackageFolder(string pacakgePath, string packageName)
        {
            if (isCreteScriptsFolder)
            {
                string scriptsFolderPath = Path.Combine(pacakgePath, "Scripts");
                Directory.CreateDirectory(scriptsFolderPath);

                //创建Editor和Runtime文件夹
                string editorFolderPath = Path.Combine(scriptsFolderPath, "Editor");
                string runtimeFolderPath = Path.Combine(scriptsFolderPath, "Runtime");

                Directory.CreateDirectory(editorFolderPath);
                Directory.CreateDirectory(runtimeFolderPath);

                // Create .asmdef files
                //这里的asmdef的文件的包名是否首字母大写？？
                string editorAsmdefPath = Path.Combine(editorFolderPath, $"{packageName}.Editor.asmdef");
                string runtimeAsmdefPath = Path.Combine(runtimeFolderPath, $"{packageName}.Runtime.asmdef");

                AsmdefConfigProcess.CreateAsmdefContent(editorAsmdefPath, true);
                AsmdefConfigProcess.CreateAsmdefContent(runtimeAsmdefPath, false);
            }
            if (isCreteTestsFolder)
            {
                //TODO 创建Tests文件夹。。。。

                string testsFolderPath = Path.Combine(pacakgePath, "Tests");
                Directory.CreateDirectory(testsFolderPath);

                string testseEditorFolderPath = Path.Combine(testsFolderPath, "Editor");
                string testseRuntimeFolderPath = Path.Combine(testsFolderPath, "Runtime");

                Directory.CreateDirectory(testseEditorFolderPath);
                Directory.CreateDirectory(testseRuntimeFolderPath);

                string testseEditorAsmdefPath = Path.Combine(testseEditorFolderPath, $"{packageName}.Editor.Tests.asmdef");
                string testseRuntimeAsmdefPath = Path.Combine(testseRuntimeFolderPath, $"{packageName}.Runtime.Tests.asmdef");

                AsmdefConfigProcess.CreateAsmdefContent(testseEditorAsmdefPath, true);
                AsmdefConfigProcess.CreateAsmdefContent(testseRuntimeAsmdefPath, false);
            }
        }

        #endregion

        #region 安装包

        /// <summary>
        /// 安装包
        /// </summary>
        /// <param name="creteResult"></param>
        /// <param name="selectPath"></param>
        /// <param name="packagePath"></param>
        private void InstallPackage(string selectPath, string packagePath)
        {
            //如果直接创建到了Packages文件加中，那么就不需要手动添加到工程中，Unity会自动添加
            if (File.Exists(Path.Combine(selectPath, "manifest.json"))) return;

            //TODO 添加包到工程中
            PackageInstaller.InstallPackageFromDisk(packagePath);
        }
        #endregion
    }
}


